package com.jy.dao.impl;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

import com.jy.dao.UserDao;
import com.jy.entity.Authority;
import com.jy.entity.User;
import com.jy.util.DbUtil;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

public class UserDaoImpl implements UserDao {
	QueryRunner runner=new QueryRunner();
	//判断登录
	@Override
	public User getUser(String name, String pwd) throws SQLException {
		String sql="select *from user where uname=? and upass=?";
		Connection conn= DbUtil.getconn();
		User user=runner.query(conn,sql,new BeanHandler<User>(User.class),name,pwd);
		conn.close();
		return user;
	}
	//根据用户名查权限
	@Override
	public List<Authority> getauthority(int uid) throws SQLException {
		Connection conn=DbUtil.getconn();
		String sql="select *from myauth where uid=?";
		List<Authority> list=runner.query(conn, sql,new BeanListHandler<Authority>(Authority.class),uid);
		conn.close();
		return list;
	}

	@Override
	public int updatevip(int userid) throws SQLException {
		Connection conn=DbUtil.getconn();
		String sql="update user2role set roleid=2 where userid=?";
		int n=runner.update(conn,sql,userid);
		return n;
	}

}
